//
//  ViewController.swift
//  登录
//
//  Created by ming on 16/10/14.
//  Copyright © 2016年 ming. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UIWebViewDelegate {

    @IBOutlet weak var webVIew: UIWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let string = Bundle.main.path(forResource: "logo.html", ofType: nil);
        print(string)
       let url = NSURL(fileURLWithPath: string!)
        let rquest = URLRequest(url: url as URL)
        webVIew.loadRequest(rquest)
        webVIew.delegate = self;
        
    }
    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        
        if request.url?.absoluteString.hasPrefix("http://52it.me/") != false {
//
            let user = webVIew.stringByEvaluatingJavaScript(from: "document.getElementsByTagName('input')[0].value;") ?? ""
            
            
            let passw = webVIew.stringByEvaluatingJavaScript(from: "document.getElementById('passw').value") ?? ""
            let remenber = webVIew.stringByEvaluatingJavaScript(from: "document.getElementsByTagName('input')[2].value;")
            print("是否记住密码:\(remenber)")
            print("用户名:\(user)+密码:\(passw)")
            print(request.url?.absoluteString)
            
            return true
        }
        
        return true
    }
    
    func webViewDidFinishLoad(_ webView: UIWebView) {
        
        
    }
   

}

